package com.prs.crm.dao.cdxh.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.prs.crm.dao.cdxh.PrintingDao;
import com.prs.crm.dao.impl.BaseDaoImpl;
import com.prs.crm.domain.cdxh.molding.MoldingTeam;
import com.prs.crm.domain.cdxh.printing.Printing;
import com.prs.crm.domain.cdxh.production.ProvideRegime;

/**
 * @author LanXiaoGang
 * @E-mail:lan9liang@163.com
 * @qq:7857553326
 * @version 创建时间：2010-12-7 上午09:44:18
 * 简单说明
 */

public class PrintingDaoImpl extends BaseDaoImpl<Printing> implements
		PrintingDao {

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public Printing getPrinting(final String podductCode,final String orderPlan) {
		return (Printing) this.getHibernateTemplate().execute(
				new HibernateCallback() {
					public Object doInHibernate(Session session)
							throws HibernateException {
						Criteria criteria = session.createCriteria(Printing.class);
						criteria.add(Restrictions.eq("printCode",podductCode));
						criteria.add(Restrictions.eq("printOrderPlan", orderPlan));						
						List<Printing> result = criteria.list();
						if (result.size() == 0) {
							return null;
						} else {
							return result.get(0);
						}
					}
				});
	}

	@Override
	public void saveOrPrinting(Printing printing) {
		this.getHibernateTemplate().saveOrUpdate(printing);
		
	}
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public List<Printing> getPrintingOrderpLan(final String orderplan) {
		return (List<Printing>)this.getHibernateTemplate().execute(
			      new HibernateCallback() {   
						public Object doInHibernate(Session session) throws HibernateException {
				        	Criteria criteria = session.createCriteria(Printing.class);
				        	criteria.add(Restrictions.eq("printOrderPlan", orderplan));		        	
				        	List<Printing> result = criteria.list();				        	
				        		return result;				        	
				        }   
				 } );
	}

	@Override
	public Printing getPrintingByPrintCode(final String printCode) {
		return (Printing) this.getHibernateTemplate().execute(
				new HibernateCallback() {
					public Object doInHibernate(Session session)
							throws HibernateException {
						Criteria criteria = session.createCriteria(Printing.class);
						criteria.add(Restrictions.eq("printCode",printCode));					
						List<Printing> result = criteria.list();
						if (result.size() == 0) {
							return null;
						} else {
							return result.get(0);
						}
					}
				});
	}

}
